From b1c34a25dffd983df5f443c905f1655fba72252b Mon Sep 17 00:00:00 2001 From: mainframe98 Date: Mon, 19 Jun 2017 19:20:43 +0200 Subject: [PATCH] Fix the tableExists method of MysqlBase The table name generated by Database::tableName() does not work in MysqlBase's tableExist method, as the syntax of SHOW TABLES does not function like other foreign db queries. It instead should use FROM $database rather than the database name in front of the table name. Bug: T168207 Change-Id: I7806090eaa647959fd34de8bc606eeb952161529 --- .../libs/rdbms/database/DatabaseMysqlBase.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php b/includes/libs/rdbms/database/DatabaseMysqlBase.php index 50ead83b20..e237ef4899 100644 --- a/includes/libs/rdbms/database/DatabaseMysqlBase.php +++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php @@ -532,11 +532,25 @@ abstract class DatabaseMysqlBase extends Database { return true; // already known to exist and won't show in SHOW TABLES anyway } + // Split database and table into proper variables as Database::tableName() returns + // shared tables prefixed with their database, which do not work in SHOW TABLES statements + list( $database, $schema, $prefix, $table ) = $this->qualifiedTableComponents( $table ); + + $table = $prefix . $table; + // We can't use buildLike() here, because it specifies an escape character // other than the backslash, which is the only one supported by SHOW TABLES $encLike = $this->escapeLikeInternal( $table, '\\' ); - return $this->query( "SHOW TABLES LIKE '$encLike'", $fname )->numRows() > 0; + // If the database has been specified (such as for shared tables), add a FROM $database clause + if ( $database !== '' ) { + $database = $this->addIdentifierQuotes( $database ); + $query = "SHOW TABLES FROM $database LIKE '$encLike'"; + } else { + $query = "SHOW TABLES LIKE '$encLike'"; + } + + return $this->query( $query, $fname )->numRows() > 0; } /** -- 2.20.1